# -*- coding: utf-8 -*-
from datetime import timedelta

from utils.operators.spark_submit import SparkSubmitOperator
from airflow.operators.bash import BashOperator

from jms.dim import jms_dim__dim_lmdm_sys_network
from jms.dwd import jms_dwd__dwd_barscan_send_dt, jms_dwd__dwd_barscan_arrival_dt

jms_dm__dm_barscan_send_to_arrival_exception_dt = SparkSubmitOperator(
    task_id='jms_dm__dm_barscan_send_to_arrival_exception_dt',
    email=['wangbiao@yl-scm.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_barscan_send_to_arrival_exception_dt_{{ execution_date | date_add(1) | cst_ds }}',
    pool_slots=5,
    driver_memory='4G',
    driver_cores=2,
    executor_memory='8G',
    executor_cores=4,
    num_executors=10,
    conf={'spark.executor.memoryOverhead': 2048,
          'spark.core.connection.ack.wait.timeout': 300,
          'spark.default.parallelism': 600,
          'spark.locality.wait': 60,
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 300,
              'hive.exec.max.dynamic.partitions.pernode': 300,
              },
    jars='hdfs:///scheduler/jms/spark/wangbiao/report/dm_barscan_send_to_arrival_exception/common-1.0-SNAPSHOT.jar',  # 依赖 jar 包
    java_class='com.yunlu.bigdata.jobs.export.SendToArrivalExceptionDetail',  # spark 主类
    application='hdfs:///scheduler/jms/spark/wangbiao/report/dm_barscan_send_to_arrival_exception/original-jobs-1.0-SNAPSHOT.jar',
    # spark jar 包
    application_args=['{{ execution_date | date_add(-6) | cst_ds }}','{{ execution_date | cst_ds }}'],  # 参数dt 跑数据当天
    execution_timeout=timedelta(hours=6),
)

upload__dm_barscan_send_to_arrival_exception_dt = BashOperator(
    task_id="upload__dm_barscan_send_to_arrival_exception_dt",
    email=['wangbiao@yl-scm.com','yl_bigdata@yl-scm.com'],
    pool='unlimited_pool',
    bash_command='jms/oss/dm_barscan_send_to_arrival_exception_dt/upload_dm_barscan_send_to_arrival_exception_dt.sh',
)

# 设置依赖
upload__dm_barscan_send_to_arrival_exception_dt << jms_dm__dm_barscan_send_to_arrival_exception_dt << [
    jms_dwd__dwd_barscan_send_dt,
    jms_dim__dim_lmdm_sys_network,
    jms_dwd__dwd_barscan_arrival_dt
]

